SpaceToDepth ================= 将输入张量的空间维按块(block)重组到深度通道(channel)中。 假设输入形状为: \[N, H, W, C\],块大小为 B,则输出形状为: .. math:: \text{out\_shape} = [N, H/ B, W / B, C * B * B] 对应元素映射为: .. math:: output[n, h_{out}, w_{out}, c * B * B + (l * B + m)] = input[n, h_{out} * B + l, w_{out} * B + m, c] 输入: - **input** - 输入数据地址,按 NHWC 存储。 - **in_shape** - 指向长度为4的数组,表示输入维度 \[N, H, W, C\]。 - **block** - block 大小。 - **data_size** - 每个元素的字节大小。 - **core_mask(int, 可选)** - 核掩码(仅适用于共享存储版本)。 输出: - **output** - 输出数据地址。 支持平台: ``FT78NE`` ``MT7004`` .. note:: - FT78NE 支持 fp32, fp64, cplx64, cplx128, int16, int8, int32 - MT7004 支持 fp32, fp16, cplx64, int16, int32 **共享存储版本:** .. c:function:: void i8_spacetodepth_s(int8_t* input, int8_t* output, const int* in_shape, int block, int data_size, int core_mask) .. c:function:: void i16_spacetodepth_s(int16_t* input, int16_t* output, const int* in_shape, int block, int data_size, int core_mask) .. c:function:: void i32_spacetodepth_s(int32_t* input, int32_t* output, const int* in_shape, int block, int data_size, int core_mask) .. c:function:: void hp_spacetodepth_s(half* input, half* output, const int* in_shape, int block, int data_size, int core_mask) .. c:function:: void fp_spacetodepth_s(float* input, float* output, const int* in_shape, int block, int data_size, int core_mask) .. c:function:: void dp_spacetodepth_s(double* input, double* output, const int* in_shape, int block, int data_size, int core_mask) .. c:function:: void c64_spacetodepth_s(float* input, float* output, const int* in_shape, int block, int data_size, int core_mask) .. c:function:: void c128_spacetodepth_s(double* input, double* output, const int* in_shape, int block, int data_size, int core_mask) **C调用示例:** .. code-block:: c :linenos: :emphasize-lines: 9 #include int main(int argc, char* argv[]) { float *input = (float *)0xA0000000; // 多核版:输入在 DDR 区域 float *output = (float *)0xB0000000; // 多核版:输出在 DDR 区域 int in_shape[4] = {1, 8, 8, 1}; // N,H,W,C int block = 2; int core_mask = 0xff; fp_spacetodepth_s(input, output, in_shape, block, sizeof(float), core_mask); return 0; } **私有存储版本:** .. c:function:: void i8_spacetodepth_p(int8_t* input, int8_t* output, const int* in_shape, int block, int data_size) .. c:function:: void i16_spacetodepth_p(int16_t* input, int16_t* output, const int* in_shape, int block, int data_size) .. c:function:: void i32_spacetodepth_p(int32_t* input, int32_t* output, const int* in_shape, int block, int data_size) .. c:function:: void hp_spacetodepth_p(half* input, half* output, const int* in_shape, int block, int data_size) .. c:function:: void fp_spacetodepth_p(float* input, float* output, const int* in_shape, int block, int data_size) .. c:function:: void dp_spacetodepth_p(double* input, double* output, const int* in_shape, int block, int data_size) .. c:function:: void c64_spacetodepth_p(float* input, float* output, const int* in_shape, int block, int data_size) .. c:function:: void c128_spacetodepth_p(double* input, double* output, const int* in_shape, int block, int data_size) **C调用示例:** .. code-block:: c :linenos: :emphasize-lines: 8 #include int main(int argc, char* argv[]) { float *input = (float *)0x10000000; // 单核版:输入在 L2 float *output = (float *)0x10010000; // 单核版:输出在 L2 int in_shape[4] = {1, 8, 8, 1}; int block = 2; fp_spacetodepth_p(input, output, in_shape, block, sizeof(float)); return 0; }